package com.mccken.demo.io.netty;

import java.util.ArrayList;
import java.util.List;

import com.mccken.demo.io.pojo.Item;
import com.mccken.demo.io.netty.client.BeanFactory;
import com.mccken.demo.io.netty.client.NettyClient;
import com.mccken.demo.io.pojo.Order;
import com.mccken.demo.io.service.OrderService;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2022-04-30 22:14
 **/
public class ClientServer {

//	public static void main(String[] args) {
//		NettyClient nettyClient = new NettyClient();
//		nettyClient.start("127.0.0.1", 5567);
//		BeanFactory beanFactory = new BeanFactory(nettyClient);
//		OrderService orderService = beanFactory.getBean(OrderService.class);
//
//		List<Item> items = Arrays.asList(
//				Item.builder()
//						.itemId(2001L)
//						.price(100L)
//						.title("铅笔")
//						.build(),
//				Item.builder()
//						.itemId(2002L)
//						.price(50L)
//						.title("橡皮")
//						.build()
//		);
//
//		for (int i = 0; i < 1; i++) {
//			Order order = orderService.submitOrder(1001L, items);
//			System.out.println("返回数据： " + JSONUtil.toJsonStr(order));
//		}
//
//		nettyClient.close();
//	}

	public static void main(String[] args) {
		NettyClient nettyClient = new NettyClient();

		nettyClient.start("127.0.0.1", 5567);

		BeanFactory beanFactory = new BeanFactory(nettyClient);

		OrderService orderService = beanFactory.getBean(OrderService.class);

		List<Item> itemList = new ArrayList<>();
		Item item = new Item();
		item.setItemId(2001L);
		item.setPrice(100L);
		item.setTitle("铅笔");
		itemList.add(item);

		item = new Item();
		item.setItemId(2002L);
		item.setPrice(50L);
		item.setTitle("橡皮");
		itemList.add(item);

		for (int i = 0; i < 1; i++) {
			Order order = orderService.submitOrder(1001L, itemList);
			System.out.println("返回数据：" + order);
		}

		nettyClient.close();

	}
}
